#include "TcpServer.hpp"

#include <memory>
using namespace Reactor_ns;
static void usage(const string& proc)
{
    cerr<< "usage:\n\t" << proc << " port" << endl;
}

void calculate(Connection *conn)
{
    
    while(!conn->_inbuffer.empty())
    {
        logMessage(DEBUG, "[%d]:%s", conn->_sock, conn->_inbuffer.c_str());
        conn->_inbuffer = "";
        conn->_outbuffer += "server# 收到消息，over! \n";
        conn->_sender(conn);
    }

}
int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        usage(argv[1]);
        exit(USAGE_ERR);
    }
    uint16_t port = atoi(argv[1]);
    unique_ptr<TcpServer> tsp(new TcpServer(calculate, port));
    tsp->InitServer();
    tsp->Dispatcher();

    return 0;
}